package cn.qyd;

/**
 * @author 邱运铎
 * @date 2024-03-05 10:57
 */
public class BinaryComputeDemo {
    public static void main(String[] args) {
        int a = 60, b = 30;
        System.out.println("a = " + a + "的二进制是： " + Integer.toBinaryString(a));
        System.out.println("b = " + b + "的二进制是： " + Integer.toBinaryString(b));

        int c = a & b;
        System.out.println("a & b : " + c + ", c的二进制是： " + Integer.toBinaryString(c));

        c = a | b;
        System.out.println("a | b : " + c + ", c的二进制是： " + Integer.toBinaryString(c));

        c = a ^ b;
        System.out.println("a ^ b : " + c + ", c的二进制是： " + Integer.toBinaryString(c));

        c = ~a;
        System.out.println("~a : " + c + ", c的二进制是： " + Integer.toBinaryString(c));

        c = a << 2;
        System.out.println("a << 2 : " + c + ", c的二进制是： " + Integer.toBinaryString(c));

        c = a >> 2;
        System.out.println("a >> 2 : " + c + ", c的二进制是： " + Integer.toBinaryString(c));

        c = a >>> 2;
        System.out.println("a >>> 2 : " + c + ", c的二进制是： " + Integer.toBinaryString(c));
        //交换a和b的值
        a = a^b;
        b = a^b;
        a = a^b;
        System.out.println(a + "-------"  + b);

    }
}
